<script setup lang="ts">
import {onBeforeMount, ref} from "vue";
import {getCookie, setCookie} from "@/util/cookieUtil";
import {getWebNotice} from "@/api/system/notice";
import {ECode} from "@/util/commonUtil";

const showNotice = ref<boolean>(false)
const content = ref<any>({})

onBeforeMount(() => {
  getNotice()
})

function getNotice() {
  getWebNotice().then((res: any) => {
    if (res.code == ECode.SUCCESS) {
      content.value = res.data
      let webNoticeUid = getCookie('webNotice')
      // 判断是否点击过公告
      showNotice.value = (webNoticeUid != content.value.uid);
    }
  })
}

function closeNotice() {
  showNotice.value = false
  if (!content.value) {
    return
  }
  setCookie("webNotice", content.value.uid, 30)
}
</script>

<template>
  <a-modal v-model:open="showNotice" centered :closable="false">
    <template #title>
      <span class="block w-full text-center text-xl">
        {{ content.title }}
      </span>
    </template>
    <div class="webNotice-main">
      <span class="flex flex-col justify-center items-center min-h-40 notice-content" v-html="content.content"
            v-highlight></span>
    </div>
    <template #footer>
      <a-button type="primary" class="w-24 flex text-center justify-center items-center m-auto" @click="closeNotice">
        已阅
      </a-button>
    </template>
  </a-modal>
</template>

<style scoped lang="less">

</style>
